<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    /**
 * @param {number[]} arr
 * @param {number} k
 * @return {number}
 */
    var queInts = function (arr, k) {
      //以对象来存储数据，key为字符，value为字符的个数
      const obj = {};
      arr.forEach(char => {
        obj[char] = obj[char] ? obj[char] + 1 : 1;
      });
      //按数量进行升序排序
      const sortedKey = Object.keys(obj).sort((a, b) => obj[a] - obj[b]);
      let count = 0;
      const len = sortedKey.length;
      for (let i = 0; i < len; i++) {
        //统计个数
        count += obj[sortedKey[i]]
        if (count === k) return len - i - 1;
        if (count > k) return len - i
      }
    };
    console.log(queInts(arr = [4, 3, 1, 1, 3, 3, 2], k = 3))
  </script>
</body>

</html>